import java.util.*;
//题目网址
//https://www.nowcoder.com/practice/
// d281619e4b3e4a60a2cc66ea32855bfa?tpId=49&&tqId=29370&rp=1&ru=/activity/oj&qru=/ta/2016test/question-ranking
 class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        ListNode slow = A;
        ListNode fast = A;

        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }

        ListNode cur = slow.next;
        ListNode curN = null;

        while (cur != null) {
            curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }

        ListNode newCur = A;
        while (newCur != slow && newCur.next != slow) {
            if (newCur.val != slow.val) {
                return false;
            }
            slow = slow.next;
            newCur = newCur.next;
        }
        return true;
    }
}